package com.stp.event.listener;

import com.stp.event.entity.*;
import com.stp.event.service.impl.PayStrategyContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

@Component
public class TwoPayApplicationListener {

    @Autowired
    private PayStrategyContext payStrategyContext;


    @EventListener(PayApplicationEvent.class)
    public void handlePayApplicationEvent(PayApplicationEvent event){
        PayEventModel eventModel = event.getEventModel();
        PayEntity payInfo = eventModel.getPayInfo();
        String model = eventModel.getModel();
        payStrategyContext.getResource(model).pay(payInfo);

        //第二种策略
        /*if(eventModel instanceof AliPayEventEntity){
            System.out.println("支付宝支付 " + eventModel.toString());
        }

        if(eventModel instanceof WxPayEventEntity){
            System.out.println("微信支付 " + eventModel.toString());
        }*/
    }
}
